//
//  UICustomSlider.m
//  UISliderAnimation
//
//  Created by ShiMac on 15/5/23.
//  Copyright (c) 2015年 guoyan. All rights reserved.
//

#import "UICustomSlider.h"
#import "UIPopView.h"



@interface UICustomSlider ()
{
    UIPopView *popView_;

}
@end


@implementation UICustomSlider

-(id)initWithFrame:(CGRect)frame{
    
    if (self=[super initWithFrame:frame]) {

        
        
        popView_=[[UIPopView alloc] initWithFrame:CGRectZero];

        [self addSubview:popView_];
        
    }
    return self;
    
}

-(CGRect)thumbRect
{
    CGRect rect1=[super thumbRectForBounds:self.bounds trackRect:[super trackRectForBounds:self.bounds] value:self.value];

    return rect1;
    
}

-(void)adjustPopView
{
    
    CGRect rect=[self thumbRect];                   //按钮frame
    
    
    CGRect popFrame=CGRectInset(rect, -50,-10);
    
    popFrame.origin.y=popFrame.origin.y-popFrame.size.height/2-13;
    
    popView_.frame=popFrame;
    [popView_ setString:[NSString stringWithFormat:@"%f",self.value]];
    [popView_ setColor:[UIColor redColor]];

    
    
    
    
    
    
    
}



- (BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
{
    BOOL begin = [super beginTrackingWithTouch:touch withEvent:event];
    if (begin) {
        
        
        [self adjustPopView];
        
        [popView_ showAnimation];
        
        
        
        
        
    }
    return begin;
}

- (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
{
    BOOL continueTrack = [super continueTrackingWithTouch:touch withEvent:event];
    if (continueTrack) {
        
        [self adjustPopView];

        
    }else{
        
        
        NSLog(@"continueend");
    }
    
    
    
    return continueTrack;
}

- (void)cancelTrackingWithEvent:(UIEvent *)event
{
    NSLog(@"cancle");
    [super cancelTrackingWithEvent:event];
    [popView_ hideAnimation];

}

- (void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
{
    [super endTrackingWithTouch:touch withEvent:event];
    NSLog(@"endTrack");
    [popView_ hideAnimation];
}









@end
